package MyApp.Controller
{
	import MyApp.Model.Well;
	import MyApp.Model.WellObsRecord;
	import MyApp.Model.WellPrdRecord;
	import MyApp.Model.proxy.WellProxy;
	
	import components.well.ObservationRecord;
	import components.well.ProductionRecord;
	import components.well.WellWindow;
	
	import custom.pager.Pager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	public class WellCommand extends SimpleCommand
	{
		public function WellCommand()
		{
			super();
		}
		private function get proxy():WellProxy{
			if(!facade.hasProxy(WellProxy.NAME)){
				facade.registerProxy(new WellProxy(WellProxy.NAME));
			}
			return facade.retrieveProxy(WellProxy.NAME) as WellProxy;
		}
		override public function execute(notification:INotification):void{
			switch(notification.getName()){
				case WellWindow.DO_REFRESH:
					proxy.loadWellList();
					break;
				case WellWindow.DO_SAVE:
					proxy.doSaveWell(notification.getBody() as Well);
					break;
				case ObservationRecord.DO_REFRESH:
					proxy.loadObsRecordList(notification.getBody() as Pager);
					break;
				case WellWindow.DO_ADD_OBSRECORD:
					proxy.addWellObsRecord(notification.getBody() as WellObsRecord);
					break;
				case WellWindow.DO_UPDATE_OBSRECORD:
					proxy.saveWellObsRecord(notification.getBody());
					break;
				case WellWindow.DO_DELETE_OBSRECORD:
					proxy.deleteWellObsRecord(notification.getBody());
					break;
				case ProductionRecord.DO_REFRESH:
					proxy.loadPrdnRecordList();
					break;
				case WellWindow.DO_ADD_PRDRECORD:
					proxy.addWellPrdRecord(notification.getBody() as WellPrdRecord);
					break;
				case WellWindow.DO_UPDATE_PRDRECORD:
					proxy.updateWellPrdRecord(notification.getBody() as WellPrdRecord);
					break;
				case WellWindow.DO_DELETE_PRDRECORD:
					proxy.deleteWellPrdRecord(notification.getBody().id);
					break;
				
			}
		}
	}
}